package com.tony.blog.server.config;

import com.tony.blog.server.shiro.ShiroVariable;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.view.freemarker.FreeMarkerConfigurer;

import java.util.HashMap;
import java.util.Map;
import java.util.Properties;

/**
 * Created with IntelliJ IDEA.
 *
 * @Title: FreemarkerConfig
 * @Auther: 皮蛋布丁
 * @Date: 2021/07/29/10:22
 * @Description: freemarker配置
 */
@Configuration
public class FreemarkerConfig {

    @Bean
    public FreeMarkerConfigurer freeMarkerConfigurer(ShiroVariable shiroVariable) {
        FreeMarkerConfigurer configurer = new FreeMarkerConfigurer();
        configurer.setTemplateLoaderPath("classpath:templates");

        Map<String,Object> variables = new HashMap<>(1);
        variables.put("shiro",shiroVariable);
        configurer.setFreemarkerVariables(variables);

        Properties settings = new Properties();
        //编码
        settings.setProperty("default_encoding","utf-8");
        //数字格式
        settings.setProperty("number_format","0.##");
        configurer.setFreemarkerSettings(settings);
        return configurer;
    }
}
